Ext.onReady(function() {
    Ext.QuickTips.init();
    var root=new Ext.tree.TreeNode({
        text:'StreamServerView',
        expanded:true
    });
    var user=(new Ext.tree.TreeNode({
            text:'Search',
            expanded:true
        })
    );
    var ViewField=new Ext.tree.TreeNode({
        text:'ViewField'
    });
    var QuoteSearch=new Ext.tree.TreeNode({
        text:'QuoteSearch'
    });
    var SortSearch=new Ext.tree.TreeNode({
        text:'SortSearch'
    });
    var BrokerSearch = new Ext.tree.TreeNode({
    	text:'BrokerSearch'
    });
    var NewsSearch = new Ext.tree.TreeNode({
    	text:'NewsSearch'
    });
    root.appendChild(user);
    user.appendChild(ViewField);
    user.appendChild(QuoteSearch);
    user.appendChild(SortSearch);
    user.appendChild(BrokerSearch);
    user.appendChild(NewsSearch);
        
    //建立根节点
    var tree=new Ext.tree.TreePanel({
        width:180,
        height:300,
        root:root
    });
   

    //中间区域
    var tabPanel = new Ext.TabPanel({
    	id:"mainTab",
        region : 'center',
        enableTabScroll : true,
        activeTab :0,
        //autoDistory:false,
        //deferredRender : true,
        //layoutOnTabChange : true,
        margins:'5 5 5 5',
        items : [{
            id : 'homePage',
            title : '首页',
            autoScroll : true,
            autoLoad:{url:'StreamServerInfo.jsp',scripts:true,nocache:true}
            //html:'<div style="position:absolute;top:40%;left:40%">欢迎来到首页!</div>'
        }],
        listeners:{
    		remove:function(tp,c){
    	  		c.hide();
    		},
    	 	render:function(tabPanels){
    			tabPanels.ownerCt.doLayout();
    		}
    	}
    });
    function treeClickViewField(){
    	var tabs = Ext.getCmp("mainTab");
    	if(!tabs.items.containsKey('tabViewField')){
    		var charttabs=
    			tabs.add({
    			id:'tabViewField',
    		   	title:'ViewField',
    			frame: true,
    			height : 420,
    			width : 700,
    			autoScroll : true,
    			closeAction:'hide',
    	        closable:true,
    	        //autoLoad:{url:'searchChart.jsp?'+paramsUrl,scripts:true,nocache:true}
    	        html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="viewField.jsp?'+paramsUrl+'"></iframe>'
    	        });    		
    		charttabs.show();
    		//tabs.activate(charttabs);
    		//tabs.setActiveTab(charttabs);
    		//tabs.doLayout();
    	}else{
    		tabs.items.item("tabViewField").show();
    	}
    }
    function treeClickQuote(){
    	var tabs = Ext.getCmp("mainTab");
    	if(!tabs.items.containsKey('tabQuote')){
    		var charttabs= 
    			tabs.add({
    			id:'tabQuote',
    		   	title:'Quote',
    			frame: true,
    			height : 420,
    			width : 700,
    			autoScroll : true,
    			closeAction:'hide',
    	        closable:true,
    	        //autoLoad:{url:'searchWar.jsp?'+paramsUrl,scripts:true,nocache:true}
    			html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="searchQuote.jsp?'+paramsUrl+'"></iframe>'	
    		}).show();
    			//charttabs.doLayout();
    		//tabs.activate(charttabs);
    		
    	}else{
    		tabs.items.item("tabQuote").show();
    	}
    }
    function treeClickSort(){
    	var tabs = Ext.getCmp("mainTab");
    	if(!tabs.items.containsKey('tabSort')){
    		var charttabs= 
    			tabs.add({
    			id:'tabSort',
    		   	title:'Sort',
    			frame: true,
    			height : 420,
    			width : 700,
    			autoScroll : true,
    			closeAction:'hide',
    	        closable:true,
    	        //autoLoad:{url:'searchWar.jsp?'+paramsUrl,scripts:true,nocache:true}
    			html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="searchSort.jsp?'+paramsUrl+'"></iframe>'	
    		}).show();
    			//charttabs.doLayout();
    		//tabs.activate(charttabs);
    		
    	}else{
    		tabs.items.item("tabSort").show();
    	}
    }
    function treeClickBroker(){
    	var tabs = Ext.getCmp("mainTab");
    	if(!tabs.items.containsKey('tabBroker')){
    		var charttabs= 
    			tabs.add({
    			id:'tabBroker',
    		   	title:'Broker',
    			frame: true,
    			height : 420,
    			width : 700,
    			layout:'border',
    			autoScroll : true,
    			closeAction:'hide',
    	        closable:true,
    	        html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="searchBroker.jsp?'+paramsUrl+'"></iframe>'
    	        //autoLoad:{url:'searchWar.jsp?'+paramsUrl,scripts:true,nocache:true}
    			//html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="searchWar.jsp?'+paramsUrl+'"></iframe>'	
    		}).show();
    			//charttabs.doLayout();
    		//tabs.activate(charttabs);
    	}else{
    		tabs.items.item("tabBroker").show();
    	}
    }
    function treeClickNews(){
    	var tabs = Ext.getCmp("mainTab");
    	if(!tabs.items.containsKey('tabNews')){
    		var charttabs= 
    			tabs.add({
    			id:'tabNews',
    		   	title:'News',
    			frame: true,
    			height : 420,
    			width : 700,
    			autoScroll : true,
    			closeAction:'hide',
    	        closable:true,
    	        html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="searchNews.jsp?'+paramsUrl+'"></iframe>'
    		}).show();    		
    	}else{
    		tabs.items.item("tabNews").show();
    	}
    }
    ViewField.on("click",treeClickViewField);
    QuoteSearch.on("click",treeClickQuote);
    SortSearch.on("click",treeClickSort);
    BrokerSearch.on("click",treeClickBroker);
    NewsSearch.on("click",treeClickNews);
    
    //界面显示
    new Ext.Viewport({
        title:'StreamServer View',
        layout:'border',
        items:[
        {
            region:'west',
            layout:'fit',
            width:200,
            split:true,
            collapsible:true,
            margins:'5 0 5 5',
            items:tree
        },{
            region:'center',
            width:500,
            layout:'fit',
            margins:'5 0 5 0',
            items:tabPanel
        }]
    });
    
});

